<?php $this->import('Header') ?>
	<div style="height: 10px;"></div>
	<div class="well">
		<h3>广告设置</h3>
		<div class="tab-content">
			<div id="message-box"></div>
			<div class="tab-pane active in">
				<form method="post" enctype="multipart/form-data">
					<input type="hidden" name="id" value="<?php echo !empty($ad['Id']) ? $ad['Id'] : ''; ?>">
					<input type="hidden" name="oldSrc" value="<?php echo !empty($ad['Src']) ? $ad['Src'] : ''; ?>">
					<label>广告类型</label>
					<select name="type">
						<option value="">请选择</option>
						<option value="1" <?php echo (!empty($ad['Type']) && $ad['Type'] == '1') ? ' selected ' : '' ?>>首页顶部图片</option>
						<option value="2" <?php echo (!empty($ad['Type']) && $ad['Type'] == '2') ? ' selected ' : '' ?>>(汇总攻略|最新动态)右侧广告(150 * 150)</option>
					</select>
					<label>连接地址</label>
					<input type="text" name="href" value="<?php echo !empty($ad['Href']) ? $ad['Href'] : ''; ?>" class="input-xlarge">
					<label>名称</label>
					<input type="text" name="name" value="<?php echo !empty($ad['Name']) ? $ad['Name'] : ''; ?>" class="input-xlarge">
					<label>描述</label>
					<input type="text" name="desc" value="<?php echo !empty($ad['Desc']) ? $ad['Desc'] : ''; ?>" class="input-xlarge">
					<label>价格</label>
					<input type="text" name="price" value="<?php echo !empty($ad['Price']) ? $ad['Price'] : ''; ?>" class="input-xlarge">
					<label>打开方式</label>
					<select name="target">
						<option value="1" <?php echo (!empty($ad['Target']) && $ad['Target'] == '1') ? ' selected ' : '' ?>>本窗口打开</option>
						<option value="2" <?php echo (!empty($ad['Target']) && $ad['Target'] == '2') ? ' selected ' : '' ?>>新窗口打开</option>
					</select>
					<label>选择图片文件</label>
					<input type="file" name="upfile" value="" class="input-xlarge">

					<div class="btn-toolbar">
						<button class="btn btn-primary"><i class="icon-save"></i> 保存</button>
					</div>
				</form>
			</div>
		</div>
		<div class="tab-content">
			<table class="table">
				<tbody><tr>
					<td>类型</td>
					<td>名称</td>
					<td>连接地址</td>
					<td>打开方式</td>
					<td>图片</td>
					<td style="width: 160px;">操作</td>
				</tr>
				<?php foreach ($adList as $val) { ?>
					<tr>
						<td><?php echo $val['Type'] == 1 ? '首页顶部图片' : '(汇总攻略|最新动态)右侧广告' ?> </td>
						<td><?php echo $val['Name'] ?></td>
						<td><?php echo $val['Href'] ?></td>
						<td><?php echo $val['Target'] == 1 ? '本窗口打开' : '新窗口打开' ?></td>
						<td><a href="<?php echo $_domain->www . '/File/GetImg?file=' . $val['Src'] ?>" target="_blank"><img src="<?php echo $_domain->www . '/File/GetImg?file=' . $val['Src'] ?>" style="max-width: 100px;" /></a></td>
						<td>
							<a href="/Options/Ad?id=<?php echo $val['Id'] ?>" class="btn">修改</a>
							<a href="javascript:;" onclick="del(<?php echo $val['Id'] ?>)" class="btn">删除</a>
						</td>
					</tr>
				<?php } ?>
				</tbody></table>
		</div>
	</div>
<?php $this->import('Footer') ?>
<script>
	function del(id) {
		if (confirm('确定要删除吗？')) {
			$.ajax({
				url: '/Ajax/Ad/Del',
				data: {id:id},
				type: 'post',
				dataType: 'json',
				success: function (data) {
					if (data.error == 1) {
						alert(data.data);
					} else {
						window.location.reload();
					}
				}
			});
		}
	}
</script>